package random;

public class Class1567 {
//    乘积为正数的最长子数组长度——动态规划
//    https://blog.csdn.net/m0_58086930/article/details/122585142
    public int getMaxLen(int[] nums) {
        int max=Integer.MIN_VALUE;
        int pos=0;
        int neg=0;
        int first=-1;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i]>0) {
                pos++;
            }else  if (nums[i]<0){
                neg++;
                if (first==-1){
                    first=i;
                }
            }else {
                pos=0;
                neg=0;
                first=-1;
            }
            if (neg%2==0){
                max=Math.max(max,pos+neg);
            }else {
                max=Math.max(max,i-first);
            }
        }
        return max;
    }

}
